﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Management;
using System.Text;
using WMI.NET.Abstracts;
using WMI.NET.CIM;

namespace WMI.NET.ComputerSystemHardware.MotherboardControllerPort
{
    /// <summary>
    /// The Win32_IRQResource  WMI class represents an interrupt request line (IRQ) number on a computer system running Windows. An interrupt request is a signal sent to the CPU by a device or program for time critical events. IRQ can be hardware-based or software-based.
    /// </summary>
    public class Win32_IRQResource : CIM_IRQ
    {

        private Nullable<Boolean> _Hardware;
        private Nullable<UInt32> _Vector;

        /// <summary>
        /// If TRUE, the interrupt is hardware or software based. A hardware IRQ is a physical wire from the peripheral to the programmable interrupt controller (PIC) chip through which the CPU can be notified of time-critical events. Some IRQ lines are reserved for standard devices, such as the keyboard, floppy disk drives, and the system clock. A software interrupt allows applications to get the attention of the processor.
        /// </summary>
        public Nullable<Boolean> Hardware { get { return _Hardware; } }

        /// <summary>
        /// Vector of the Windows IRQ resource. A vector contains the memory address to the function that will execute once the interrupt request is acknowledged by the CPU.
        /// </summary>
        public Nullable<UInt32> Vector { get { return _Vector; } }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="mbo"></param>
        public Win32_IRQResource(ManagementBaseObject mbo)
            : base(mbo)
        {
            _Hardware = mbo.GetBoolValue("Hardware");
            _Vector = mbo.GetUIntValue("Vector");
        }

    }

    /// <summary>
    /// 
    /// </summary>
    public class GetWin32_IRQResources : Win32Collection<Win32_IRQResource>
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override ReadOnlyCollection<Win32_IRQResource> GetCollection()
        {
            List<Win32_IRQResource> tempCollection = new List<Win32_IRQResource>();

            foreach (var s in searcher.Get())
            {

                Win32_IRQResource tempListItem = new Win32_IRQResource(s);
                tempCollection.Add(tempListItem);
            }

            return tempCollection.AsReadOnly();
        }

        /// <summary>
        /// 
        /// </summary>
        public GetWin32_IRQResources() : base("SELECT * FROM Win32_IRQResource") { }

    }
}
